/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Model;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.sql.DataSource;
import org.apache.commons.dbcp.cpdsadapter.DriverAdapterCPDS;
import org.apache.commons.dbcp.datasources.SharedPoolDataSource;

/**
 *
 * @author Nguyen Hung
 */
public class DAO {

    private static DataSource ds;

    static {
        try {
            DriverAdapterCPDS cpds = new DriverAdapterCPDS();
            cpds.setDriver("com.mysql.jdbc.Driver");
            cpds.setUrl("jdbc:mysql://localhost:3306/shoppingonline?useUnicode=true&characterEncoding=UTF-8&autoReconnect=true");
            cpds.setUser("root");
            cpds.setPassword("123456");
            SharedPoolDataSource tds = new SharedPoolDataSource();
            tds.setConnectionPoolDataSource(cpds);
            tds.setMaxActive(100);
            tds.setMaxWait(1000);
            ds = tds;
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public static Connection getConnection() {
        Connection connection = null;
        try {

            connection = ds.getConnection();
        } catch (SQLException ex) {
            Logger.getLogger(DAO.class.getName()).log(Level.SEVERE, null, ex);
        }

        return connection;
    }
    public static void main(String[] args) {
        System.out.println(getConnection());
    }

 
}
